
public class Demo5 {
	private static int cnt=5;
	private static int len=5;
	public static void main1(String[] args) throws InterruptedException {
		Thread t1=new Thread(()->{
			while(cnt!=0) {
				System.out.println("hello thread1");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
				cnt--;
			}
		});
		Thread t2=new Thread(()->{
			while(len!=0) {
				System.out.println("hello thread2");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
				len--;
			}
		});
//	t1.run();
//	t2.run();
		t1.start();
		t1.join();
		t2.start();
	}

	public static void main2(String[] args) throws InterruptedException {
		Thread t1=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("0");
		});
		Thread t2=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("1");
		});
		Thread t3=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("2");
		});
		Thread t4=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("3");
		});
		Thread t5=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("4");
		});
		Thread t6=new Thread(()-> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("5");
		});
		t1.start();
		t1.join();
		t2.start();
		t2.join();
		t3.start();
		t3.join();
		t4.start();
		t4.join();
		t5.start();
		t5.join();
		t6.start();
		t6.join();
	}
	public static void main(String[] args) {
		Thread t = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("1");
			}
		});
		t.start();
		System.out.println("2");
	}

}
